import Vue from 'vue';
import MenuContext from './MenuContext.vue';

export default {
  bindClose(app, div, listeners) {
    app.close = listeners.close = () => {
      try {
        app.$destroy();
        div.remove();
        app.$el.remove();
      } catch (e) {
        console.log(e);
      }
    };
  },
  showMenuContext(menuContext, {x, y}) {
    let div = document.createElement('div');
    document.body.append(div);
    let listeners = {};
    let app = new Vue({
      render: (createElement) => {
        return createElement(MenuContext, {
          props: {menuContext, x, y},
          on: listeners
        });
      }
    });
    this.bindClose(app, div, listeners);
    app.$mount(div);
    return app;
  },
};